<%--
  Created by IntelliJ IDEA.
  User: kurong
  Date: 2021/10/8
  Time: 10:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
</head>
<body>
<h1> 欢迎登录 </h1>
<span>
    ${loginMsg}
</span>

<form method="post" action="${pageContext.request.contextPath}/test/login" class="lognForm">
    账号: <input type="text" name="username" class="username"/><br/>
    密码: <input type="password" name="password" class="password"/><br/>
    <input class="subBtn" type="button" value="登录"/><br/>
</form>


<script src="${pageContext.request.contextPath}/res/jquery/jquery-3.5.1.js"></script>
<script>

    var PUBLIC_KEY = '';


    $(".submit").click(function () {

        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/resregister",
            dataType: 'json',
            success: function (result) {
                PUBLIC_KEY = result.data; //获取公钥

                var encrypt = new JSEncrypt();
                encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

                var username = $(".username").val();
                var encryptusername = encrypt.encrypt(username);

                var password = $(".password").val();
                var encryptpassword = encrypt.encrypt(password);


                // console.log('公钥:%o', PUBLIC_KEY);
                // console.log('加密后数据:%o', encrypted);


                if (checkTel() && checkEmail() && checkPassword() && checkCode() && checkRePassword()) {
                    // $(".password").val(encrypted);
                    $(".username").val(encryptusername);
                    $(".password").val(encryptpassword);
                    $(".registForm").submit();
                }

            }
        });
    });


</script>
</body>


</html>
